const rootValue = 16
const designWidth = 1920
let scale = 1
function setHtmlFontSize() {
  let width = document.body.clientWidth
  if (width < 1440) width = 1440
  scale = width / designWidth
  document.documentElement.style.fontSize = scale * rootValue + 'px'
}
function rem2px(rem: number) {
  let px = 0
  px = rem * scale * rootValue
  return px
}
function px2rem(px: number) {
  let rem = 0
  rem = scale * (px / rootValue)
  return rem
}
function initPx2Rem() {
  setHtmlFontSize()
  window.addEventListener('resize', _evt => {
    setHtmlFontSize()
  })
}

export {
  initPx2Rem, rem2px, px2rem
}